<?php
include '../admin_head.php';
$id = $_GET['id'];

$sql = "select o.id,o.user_name,o.addtime,o.status,r.name,r.phone,r.address from ".PRE."order o,".PRE."order_receiver r where  o.rec_id = r.id and o.id='{$id}' order by o.id";
$result = mysql_query($sql);
$orderlist = mysql_fetch_assoc($result);

//查询订单中所有商品
$sql = "select  g.id,name,image,og.price,num from ".PRE."order_goods og,".PRE."goods g  where og.goods_id = g.id and order_id='{$id}'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){$goodslist[] = $row;}

if(empty($goodslist)) {echo '<meta http-equiv="Refresh" content="0; url=index.php"/>';exit;}
?>

	<div class="admin_main_nav">订单管理&gt;&gt;订单详情</div>
	<div id="user_index" class="admin_main_index">
		<div class="width">
			<div class="user_index_title">
			</div>
			<div>
				<table width="800" align="center">
					<tr>
						<th>订单号：</th>
						<th>会员名称：</th>
						<th>下单时间：</th>
						<th>订单状态：</th>
						<th>操作</th>
					</tr>
					<tr>
						<td><?php echo $orderlist['id']?></td>
						<td><?php echo $orderlist['user_name']?></td>
						<td><?php echo date('Y-m-d',$orderlist['addtime'])?></td>
						<td width="80"><?php 
							switch($orderlist['status']){
								case 0:
								?>
								<div class="action">
								<div class="fl"><a class="sent" href="action.php?a=sent&id=<?php echo $id ?>"><div class="icon fl sent_i"></div><div class="fl">发货</div></a></div>
								</div>
								<?php			
									break;
								case 1:
									echo '<font color="red">等待收货</font>';
									break;
								case 2:
									echo '<font color="green">交易完成</font>';
									break;
							} 
						?></td>
						<td width="80">
							<div class="action">
								<div class="fl"><a class="del" href="action.php?a=del&id=<?php echo $id ?>"><div class="icon fl del_i"></div><div class="fl">删除</div></a></div>
							</div>
						</td>
					</tr>
					<tr>
						<th>收件人详情：</th>
						<td colspan="4" style="text-align:left;"><?php echo $orderlist['name'].'　'.$orderlist['phone'].'　'.$orderlist['address']?></td>
					</tr>
				</table>
			</div>
			
		</div>
	</div>
	
	<div class="admin_main_index mt20">
		<div class="width">
			<div>
				<table width="800" align="center">
					<tr class="color">
						<th width="120">商品</th>
						<th width="300">商品名</th>
						<th>单价</th>
						<th>数量</th>
						<th>小计</th>
					</tr>
					<?php foreach($goodslist as $val):?>
					<tr>
                        <td><a href="<?php echo APP?>/detail.php?gid=<?php echo $val['id']?>" target="_top"><img src="<?php echo APP ?>/upload/<?php echo $val['image']?>"  height="80"/></a></td>
						<td><a href="<?php echo APP?>/detail.php?gid=<?php echo $val['id']?>" target="_top"><?php echo $val['name']?></a></td>
						<td><?php echo $val['price']?></td>
						<td><?php echo $val['num']?></td>
						<td><?php echo $val['price']*$val['num']?></td>
						
					</tr>
					<?php $total += $val['price']*$val['num'];endforeach;?>
					<tr class="color count">
						<td colspan="5" style="text-align:right;"><span>总计：￥<?php echo number_format($total,2,'.',',') ?> </span></td>
					</tr>
				</table>
			</div>
		</div>
	</div>
	
	

	
<?php include '../admin_footer.php'; ?>

